<?php
namespace app\admin\controller;
use think\Db;
use app\admin\model\CommonModel;

/**
 * By：wl
 * Date：2018.11
 * Function:用户列表
 */

class User extends Base
{
    public function index(){

    	//条件筛选
        $phone_s='';
        $username='';
        $start='';
        $end='';
        $where='';

        if($_GET){

            //like
            $phone_s = $_GET['phone_s']?$_GET['phone_s']:'';
            if($phone_s){
                $where['phone'] = ['like', "%{$phone_s}%"];
            }
            //like
            $username = $_GET['username']?$_GET['username']:'';
            if($username){
                $where['username'] = ['like', "%{$username}%"];
            }

            $start = strtotime($_GET['start']);
            $end = strtotime($_GET['end']);
            if($start!=null && $end!=null){
                $where['ctime'] = ['between',[$start,$end]];

            }

        }
       

        $this->assign('phone_s', $phone_s);
        $this->assign('username', $username);
        $this->assign('start', $_GET['start']);
        $this->assign('end', $_GET['end']);

        //分页查询
        $orderBy = ['id' => 'desc'];
        $lists = Db::table('users')->where($where)->order($orderBy)->paginate(12,false,['query' => request()->param()]);
        $page = $lists->render();
        $lists = $lists->all(); 
        foreach ($lists as $k => $v) {
            $lists[$k]['ctime'] = date('Y-m-d h:i:s',$lists[$k]['ctime']);
        }
        //输出
        $this->assign('lists', $lists);
        $this->assign('page', $page);

    	return view();
    }
   
   
}

